package com.jqp.config;

import cn.hutool.extra.spring.SpringUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import org.ssssssss.magicapi.core.service.MagicAPIService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

public class ApiInterceptor implements HandlerInterceptor {

    private String api;
    public ApiInterceptor(String api) {
        this.api = api;
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        MagicAPIService magicAPIService = SpringUtil.getBean(MagicAPIService.class);
        Map<String,Object> map = new HashMap<>();
        return magicAPIService.execute("get", api, map);
    }
}
